﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Communicator
{
    public class Logger
    {
        protected string _fileName;
        protected string _folder;

        public Logger(string fileName, string folder)
        {
            this._fileName = fileName;
            this._folder = folder;

            if (!Directory.Exists(folder))
                Directory.CreateDirectory(folder);
        }

        public void WriteLog(string mess)
        {
            string filePath = string.Format("{0}{1}{2}_{3}.txt", _folder, _folder.EndsWith("/") ? "" : "/", DateTime.Now.ToString("yyyyMMdd"), _fileName);

            using (StreamWriter w = new StreamWriter(filePath, true))
            {
                w.WriteLine("[{0}]{1}", DateTime.Now, mess);
            }
        }

        public void WriteLog(string mess, params object[] arg)
        {
            string filePath = string.Format("{0}{1}{2}_{3}.txt", _folder, _folder.EndsWith("/") ? "" : "/", DateTime.Now.ToString("yyyyMMdd"), _fileName);
            using (StreamWriter w = new StreamWriter(filePath, true))
            {
                w.Write("[{0}]", DateTime.Now);
                w.WriteLine(mess, arg);
            }
        }
    }
}
